package com.instpower.things.config;

import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @ClassName PropertyUtil
 * @Author: hellmash@gmail.com
 * @Date: 2020/3/18
 * @Version: 1.0.0
 * @Description: 扩展属性功能，增加属性读取的功能
 */
public class PropertyUtil extends PropertyPlaceholderConfigurer {
    private static Map<String, String> propertiesData = new LinkedHashMap<>();

    @Override
    protected String convertProperty(String propName, String propValue) {
        String value = super.convertProperty(propName, propValue);
        propertiesData.put(propName, value);
        return value;
    }

    /**
     *
     * @param key
     * @param defaultValue
     * @return
     */
    public static String getProperty(String key, String defaultValue) {
        String value = propertiesData.get(key);
        return value == null ? defaultValue : value;
    }

    /**
     *
     * @param key
     * @return
     */
    public static String getProperty(String key) {
        return getProperty(key, null);
    }
}
